package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsCollect;
import com.qf.service.CollectService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/8 20:51
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService service;
    @GetMapping("/list")
    public Object list(String userId, String valueId,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @RequestParam(defaultValue = "add_time") String sort,
                       @RequestParam(defaultValue = "desc") String order ){

        IPage<DtsCollect> list = service.list(userId, valueId, page, limit, sort, order);

        long total = list.getTotal();

        List<DtsCollect> records = list.getRecords();

        HashMap<String,Object> data = new HashMap<>();

        data.put("total", total);
        data.put("items",records);

        return ResponseUtil.ok(data);
    }


}
